package net.fiodor.log.channel {
	import net.fiodor.log.LogLevel;	

	import flash.external.ExternalInterface;	

	import net.fiodor.log.LogEvent;	
	import net.fiodor.log.channel.AbstractChannel;
	import net.fiodor.log.channel.IChannel;

	/**
	 * @author Tomasz Swierszcz, 
	 * email: tomasz.swierszcz@dreamlab.pl
	 */
	public class FireBugChannel extends AbstractChannel implements IChannel {

		public function FireBugChannel() {
			super();
		}

		public function publish(e : LogEvent) : void {
			
			if(!ExternalInterface.available) return;
		
			var methodName : String;
		
			switch(e.level) {
				
				case LogLevel.NONE : 
				
					break;
				case LogLevel.DEBUG : 
					methodName = "console.debug";
					break;
				case LogLevel.INFO : 
					methodName = "console.info";
					break;
				case LogLevel.WARN : 
					methodName = "console.warn";
					break;
				case LogLevel.ERROR : 
					methodName = "console.error";
					break;
				case LogLevel.FATAL : 
					methodName = "console.fatal";
					break;
			 			
				default : 
					methodName = "console.debug";
			}
			
			var arg : Object = e.argument;
			var txt : String = e.loggerId + " " + e.level.toString();
			txt += " - ";
			txt += analyzeObj(arg, 1);
		
			ExternalInterface.call(methodName, txt) ;
		}
	}
}
